package com.randy.recyclerviews.rangecalculator;

import com.randy.recyclerviews.helper.Range;

import java.util.List;

/**
 * 包含 header, 数据，loadmore, footer，空Placeholder 的RangeCalculator
 * Created by xudong on 2016/12/15.
 */
@Deprecated
public class SimpleListRangeCalculator2<T extends IDiffUtilHelper> extends SimpleListRangeCalculator<T> {
    public SimpleListRangeCalculator2() {
    }

    public SimpleListRangeCalculator2(boolean hasHeader, boolean hasFooter) {
        super(hasHeader, hasFooter);
    }

    /**
     * 当没有数据时，直接显示emptyview，不显示header，footer
     * 有数据时，显示header；加载完所有，显示footer
     */
    @Override
    public void updateRange(List<T> data, boolean hasMore) {
        cachedData = data;

        headerRange = Range.empty(0);
        dataRange = Range.empty(0);
        loadMoreRange = Range.empty(0);
        emptyViewRange = Range.empty(0);
        footerRange = Range.empty(0);
        itemCount = 0;

        if (data != null && data.size() > 0) {
            if (hasHeader) {
                headerRange = Range.create(itemCount, itemCount + 1);
                itemCount = headerRange.second;
            }

            dataRange = Range.create(itemCount, itemCount + data.size());
            itemCount = dataRange.second;

            if (hasMore) {
                loadMoreRange = Range.create(itemCount, itemCount + 1);
                itemCount = loadMoreRange.second;
            } else {
                if (hasFooter) {
                    footerRange = Range.create(itemCount, itemCount + 1);
                    itemCount = footerRange.second;
                }
            }
        } else {
            if (notShowEmptyFirstTime) {
                notShowEmptyFirstTime = false;
            } else {
                emptyViewRange = Range.create(itemCount, itemCount + 1);
                itemCount = emptyViewRange.second;
            }
        }
    }
}
